//
// Created by vcq on 21/4/2.
//
#include "model/require.hpp"
static void GetRequire(request& req, response& res) {
    if(!check_login(req,res)){
        return;
    }
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> _plan_id = req.get_query_value("_plan_id");
    basic_string_view<char> _finish_id = req.get_query_value("_finish_id");
    json item=mgetRequire(id,_plan_id,_finish_id);
    res.set_status_and_content(status_type::ok, item.dump(),req_content_type::json);
}
static void DeleteRequire(request& req, response& res) {
    if(!check_login(req,res)){
        return;
    }
    MDeleteRequire(req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}
static void SaveRequire(request& req, response& res) {
    if(!check_login(req,res)){
        return;
    }
    struct require finishreq1{};
    finishreq1.id = atoi(req.get_query_value("id").data());
    finishreq1.name=req.get_query_value("name");
    finishreq1.note=req.get_query_value("note");
    finishreq1._plan_id=atoi(req.get_query_value("_plan_id").data());
    finishreq1._finish_id=atoi(req.get_query_value("_finish_id").data());
    MAddRequire(finishreq1);
    res.set_status_and_content(status_type::ok);
}